package com.ttai.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.ttai.R;
import com.ttai.untils.Constant;
import com.ttai.untils.SM4.Sm4Util;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class UserHomePage extends AppCompatActivity {
    @Bind(R.id.sl_slider)
    SliderLayout slSlider;
    @Bind(R.id.btn_loginid)
    Button btnLoginid;
    @Bind(R.id.btn_idcard)
    Button btnIdcard;
    @Bind(R.id.btn_userpassword)
    Button btnUserpassword;
    @Bind(R.id.btn_user)
    Button btnUser;

    public String index;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userhomepage);

        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        TextView barTitle = (TextView)findViewById(R.id.barTitle);
        barTitle.setText("态安全");
        toolbar.setBackgroundColor(Color.parseColor("#3399FF"));
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        //透明导航栏
//        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Toast.makeText(UserHomePage.this,"11",Toast.LENGTH_SHORT).show();
//            }
//        });


        String token = Constant.getToken();
        Log.i("123", "onCreate: token" + token);
        ButterKnife.bind(this);
        addSldieLayout();

        String mingwen = "123456";
        String miyao = "jjjiiikkkodjdifd";
        byte[] mingwenbyte = mingwen.getBytes();
        byte[] miyaobyte = miyao.getBytes();

        System.out.println("1");
        try {
            System.out.println("2");
            byte[] result = Sm4Util.encrypt_Ecb_Padding(miyaobyte, mingwenbyte);
            byte[] jiemiMingWen = Sm4Util.decrypt_Ecb_Padding(miyaobyte, result);
            System.out.println("result:" + new String(result));
            System.out.println("jiemi:" + new String(jiemiMingWen));
            System.out.println("3");

        } catch (Exception e) {
            System.out.println("error" + e.getMessage());
        }
    }


    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("主界面"); //手动统计页面("SplashScreen"为页面名称，可自定义)，必须保证 onPageEnd 在 onPause 之前调用，因为SDK会在 onPause 中保存onPageEnd统计到的页面数据。
        MobclickAgent.onPause(this);
    }


    private void addSldieLayout() {
        HashMap<String, Integer> imgpath = new HashMap<>();
        imgpath.put("态安全宣传", R.drawable.taibanner);
//        imgpath.put("态安全宣传2", R.drawable.taisercuritybanner_mdpi);
//        imgpath.put("态安全宣传3", R.drawable.sercutirybanner_mdpi);

        for (String desc : imgpath.keySet()) {
            TextSliderView textSliderView = new TextSliderView(this);
            textSliderView
                    .description(desc)
                    .image(imgpath.get(desc));

            //向SlideLayout控件插入
            slSlider.addSlider(textSliderView);
            slSlider.setPresetIndicator(SliderLayout.PresetIndicators.Right_Bottom);
            slSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
            slSlider.setDuration(4000);
        }


    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("主界面"); //手动统计页面("SplashScreen"为页面名称，可自定义)
        MobclickAgent.onResume(this); //统计时长
        if (MainActivity.index == null) {
            System.out.println("11");
            index = getIntent().getStringExtra("index");
        } else {
            index = MainActivity.index;
        }
        System.out.println("index" + index);
        if (index != null) {
            if (index.equals("1")) {
                this.finish();
                Intent intent = new Intent(this, ZhiWen.class);
                startActivity(intent);
            }
        }
    }

    @OnClick({R.id.btn_loginid, R.id.btn_idcard, R.id.btn_userpassword, R.id.btn_user})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_loginid:
                Intent intent3 = new Intent();
                intent3.putExtra("value", "idcard");
                intent3.setClass(UserHomePage.this, ZhiWen.class);
                startActivity(intent3);
                break;
            case R.id.btn_idcard:
                Intent intent1 = new Intent();
                intent1.setClass(UserHomePage.this, VerifyModeModel.class);
                startActivity(intent1);
                break;
            case R.id.btn_userpassword:
                Intent intent2 = new Intent();
                intent2.putExtra("value", "userpassword");
                intent2.setClass(UserHomePage.this, ZhiWen.class);
                startActivity(intent2);
                break;
            case R.id.btn_user:
//                finish();
                Intent intent4 = new Intent();
                intent4.setClass(UserHomePage.this, User.class);
                startActivity(intent4);
                break;
        }
    }
}
